﻿using System;
using System.IO;
using Mockery.Core;
using NUnit.Framework;
using Rhino.Mocks;

namespace Mockery.UnitTest
{
    [TestFixture]
    public class DisposableContextStateTests
    {
        [Test]
        public void DisposableContextState_Count()
        {
            var state = new DisposableContextState();

            Assert.That(state.Count == 0);
        }

        [Test]
        public void DisposableContextState_Add()
        {
            var state = new DisposableContextState();

            state.Add(new MemoryStream());

            Assert.That(state.Count == 1);
        }

        [Test]
        public void DisposableContextState_AddEmptyItem()
        {
            var state = new DisposableContextState();

            state.Add(null);

            Assert.That(state.Count == 0);
        }

        [Test]
        public void DisposableContextState_Dispose()
        {
            var mocks = new MockRepository();

            var disposedItem = mocks.StrictMock<IDisposable>();
            Expect.Call(() => disposedItem.Dispose());

            var state = new DisposableContextState();

            state.Add(disposedItem);

            mocks.ReplayAll();

            state.Dispose();

            mocks.VerifyAll();

            Assert.That(state.Count == 0);
        }
    }
}